import { fileGuard } from '@kit.DataGuardKit'
import { fileIo } from '@kit.CoreFileKit'


function arrayBufferToStr(buf) {
  try {
    let array = new Uint8Array(buf);
    let jsonStr = String.fromCharCode.apply(null, array);
    console.info('arrayBufferToStr end  len:' + jsonStr.length + '  value:' + jsonStr);
    return jsonStr;
  } catch (err) {
    console.error('arrayBufferToStr exception: ' + err as string);
  }
}

export default function getFileContent(fileDir):string {
  let myFileGuard = new fileGuard.FileGuard();
  myFileGuard.openFile(fileDir, (err, fd) => {
    let jsonContent = new ArrayBuffer(40960);
    let count = fileIo.readSync(fd, jsonContent);
    let jsonBuffer = jsonContent.slice(0, count)
    let str = this.arrayBufferToStr(jsonBuffer);
    return str
  });
  return ''
}

